/**
 * 
 */
package com.cp16.tss.validation;

import java.awt.Color;

import com.cp16.tss.common.Constants;
import com.cp16.tss.form.CustomerForm;

/**
 * @author GiangHN
 * @version 1.0
 * @since 01/01/2014
 * 
 */
public class CustomerValidation {

	public static boolean validateCustomerForm(CustomerForm customerForm) {
		boolean flag;
		boolean customerIdFlag = validateCustomerIdForm(customerForm);
		boolean customerNameFlag = validateCustomerNameForm(customerForm);
		boolean customerPhoneFlag = validateCustomerPhoneForm(customerForm);
		flag = customerIdFlag && customerNameFlag && customerPhoneFlag;
		return flag;
	}

	// validate CustomerId
	public static boolean validateCustomerIdForm(CustomerForm customerForm) {
		String customerId = customerForm.getTxtCustomerId().getText();
		boolean customerIdFlag;
		if (customerId.equals(Constants.BLANK)) {
			customerForm.getLblListForCustomer().setText(
					"Customer ID is required");
			customerForm.getTxtCustomerId().setBackground(Color.PINK);
			customerIdFlag = false;
		} else if (!CommonValidation.isNummeric(customerId)) {
			customerForm.getLblListForCustomer().setText(
					"Customer ID is not right format");
			customerForm.getTxtCustomerId().setBackground(Color.PINK);
			customerIdFlag = false;
		} else {
			customerForm.getLblListForCustomer().setText("Add new Customer");
			customerIdFlag = true;
		}
		return customerIdFlag;
	}

	// validate Customer name
	public static boolean validateCustomerNameForm(CustomerForm customerForm) {
		String customerName = customerForm.getTxtCustomerName().getText();
		boolean customerNameFlag;
		if (customerName.equals(Constants.BLANK)) {
			customerForm.getLblListForCustomer().setText("Customer name is required");
			customerForm.getTxtCustomerName().setBackground(Color.PINK);
			customerNameFlag = false;
		} else if (!CommonValidation.isUsername(customerName)) {
			customerForm.getLblListForCustomer().setText("Customer name is not right format");
			customerForm.getTxtCustomerName().setForeground(Color.PINK);
			customerNameFlag = false;
		} else {
			customerForm.getLblListForCustomer().setText("Add new Customer");
			customerNameFlag = true;
		}
		return customerNameFlag;
	}

	// validate customer phone
	public static boolean validateCustomerPhoneForm(CustomerForm customerForm) {
		String customerPhone = customerForm.getTxtPhone().getText();
		boolean customerPhoneFlag = true;
		if (!customerPhone.equals(Constants.BLANK) && !CommonValidation.checkPhoneNumber(customerPhone)) {
				customerForm.getLblListForCustomer().setText("Phone is not right format");
				customerForm.getTxtPhone().setBackground(Color.PINK);
				customerPhoneFlag = false;
		}
		return customerPhoneFlag;
	}

}
